//
//  MyOrderListController.m
//  zhijianshejian
//
//  Created by admin on 16/5/24.
//  Copyright © 2016年 haoniu-duhuan. All rights reserved.
//

#import "MyOrderListController.h"
#import "MyOrderCell.h"
#import "OrderDetailController.h"
#import "PayOrderController.h"
#import "EvalProductListController.h"
#import "OrderRefundController.h"
#import "CancelReasonViewController.h"

#define MyOrderListStatus1 0
#define MyOrderListStatus2 1
#define MyOrderListStatus3 2
#define MyOrderListStatus4 4
#define MyOrderListStatus5 5

@interface MyOrderListController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,MyOrderCellDelegate>{
    int _currentPage;
    
    //全部
    UITableView * _tableView1;
    NSMutableArray * _dataSource1;
    int _currentPage1;
    //待付款
    UITableView * _tableView2;
    NSMutableArray * _dataSource2;
    int _currentPage2;
    //待发货
    UITableView * _tableView3;
    NSMutableArray * _dataSource3;
    int _currentPage3;
    //待收货
    UITableView * _tableView4;
    NSMutableArray * _dataSource4;
    int _currentPage4;
    //待评价
    UITableView * _tableView5;
    NSMutableArray * _dataSource5;
    int _currentPage5;
    
    //支付回调
    NSIndexPath * _indexPathPay;
    int _status;
    //评价回调
    NSIndexPath * _indexPathEval;
}

@end

@implementation MyOrderListController

- (IBAction)topBtnClick:(id)sender {
    UIButton * btn = (UIButton *)sender;
    for (int i = 100; i<105; i++) {
        if (i!=btn.tag) {
            UIButton * button = (UIButton *)[_topVIew viewWithTag:i];
            [button setSelected:NO];
        }
    }
    [btn setSelected:YES];
    int offsetX = (btn.tag-100)*_scrollView.frame.size.width;
    //设置_scrollViewRight偏移量
    [_scrollView setContentOffset:CGPointMake(offsetX, 0)];
    //设置buttonLine偏移量
    [self.lineBtn setFrame:CGRectMake(offsetX/5, self.lineBtn.frame.origin.y,_topVIew.frame.size.width/5, 2)];
    
    if (btn.tag==100) {
        [_tableView1.mj_header beginRefreshing];
    }else if (btn.tag==101) {
        [_tableView2.mj_header beginRefreshing];
    }else if (btn.tag==102) {
        [_tableView3.mj_header beginRefreshing];
    }else if (btn.tag==103) {
        [_tableView4.mj_header beginRefreshing];
    }else if (btn.tag==104) {
        [_tableView5.mj_header beginRefreshing];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.title = @"我的订单";
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    UIBarButtonItem * left = [[UIBarButtonItem alloc]init];
    [left setImage:[UIImage imageNamed:@"fanhui"]];
    [left setTarget:self];
    [left setAction:@selector(backPage)];
    self.navigationItem.leftBarButtonItem = left;
    
    _currentPage1 = 1;
    _currentPage2 = 1;
    _currentPage3 = 1;
    _currentPage4 = 1;
    _currentPage5 = 1;
    
    [self.topVIew setBackgroundColor:[AppConfig colorWithHexString:@"#f5f5f5"]];
    [self.topBtn1 setTitleColor:[AppConfig colorWithHexString:@"#40af77"] forState:UIControlStateSelected];
    [self.topBtn2 setTitleColor:[AppConfig colorWithHexString:@"#40af77"] forState:UIControlStateSelected];
    [self.topBtn3 setTitleColor:[AppConfig colorWithHexString:@"#40af77"] forState:UIControlStateSelected];
    [self.topBtn4 setTitleColor:[AppConfig colorWithHexString:@"#40af77"] forState:UIControlStateSelected];
    [self.topBtn5 setTitleColor:[AppConfig colorWithHexString:@"#40af77"] forState:UIControlStateSelected];
    [self.lineBtn setBackgroundColor:[AppConfig colorWithHexString:@"#40af77"]];
    [self.line setFrame:CGRectMake(0, 44, mainScreenSize.width, 0.5)];
    [self.line setBackgroundColor:[AppConfig colorWithHexString:@"#acacac"]];
    
    self.scrollView.delegate = self;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    [self.scrollView setContentSize:CGSizeMake(mainScreenSize.width*5, mainScreenSize.height-64-45)];
    
    _dataSource1 = [NSMutableArray array];
    _tableView1 = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, mainScreenSize.width, mainScreenSize.height-64-45)];
    _tableView1.dataSource = self;
    _tableView1.delegate = self;
    [_tableView1 setBackgroundColor:[AppConfig colorWithHexString:@"#f5f5f5"]];
    [_tableView1 setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.scrollView addSubview:_tableView1];
    __weak typeof(self) weakSelf = self;
    _tableView1.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^(void){
        [weakSelf getOrderListByStatus:MyOrderListStatus1 withPage:_currentPage1+1];
    }];
    MJRefreshGifHeader *header = [AppConfig getCustomMJRefreshGifHeader];
    [header setRefreshingBlock:^(void){
        [weakSelf getOrderListByStatus:MyOrderListStatus1 withPage:1];
    }];
    _tableView1.mj_header = header;
    [_tableView1.mj_header beginRefreshing];
    
    _dataSource2 = [NSMutableArray array];
    _tableView2 = [[UITableView alloc]initWithFrame:CGRectMake(mainScreenSize.width, 0, mainScreenSize.width, mainScreenSize.height-64-45)];
    _tableView2.dataSource = self;
    _tableView2.delegate = self;
    [_tableView2 setBackgroundColor:[AppConfig colorWithHexString:@"#f5f5f5"]];
    [_tableView2 setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.scrollView addSubview:_tableView2];
    _tableView2.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^(void){
        [weakSelf getOrderListByStatus:MyOrderListStatus2 withPage:_currentPage2+1];
    }];
    MJRefreshGifHeader *header2 = [AppConfig getCustomMJRefreshGifHeader];
    [header2 setRefreshingBlock:^(void){
        [weakSelf getOrderListByStatus:MyOrderListStatus2 withPage:1];
    }];
    _tableView2.mj_header = header2;
    //[self getOrderListByStatus:MyOrderListStatus2 withPage:1];
    
    _dataSource3 = [NSMutableArray array];
    _tableView3 = [[UITableView alloc]initWithFrame:CGRectMake(mainScreenSize.width*2, 0, mainScreenSize.width, mainScreenSize.height-64-45)];
    _tableView3.dataSource = self;
    _tableView3.delegate = self;
    [_tableView3 setBackgroundColor:[AppConfig colorWithHexString:@"#f5f5f5"]];
    [_tableView3 setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.scrollView addSubview:_tableView3];
    _tableView3.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^(void){
        [weakSelf getOrderListByStatus:MyOrderListStatus3 withPage:_currentPage3+1];
    }];
    MJRefreshGifHeader *header3 = [AppConfig getCustomMJRefreshGifHeader];
    [header3 setRefreshingBlock:^(void){
        [weakSelf getOrderListByStatus:MyOrderListStatus3 withPage:1];
    }];
    _tableView3.mj_header = header3;
    //[self getOrderListByStatus:MyOrderListStatus3 withPage:1];
    
    _dataSource4 = [NSMutableArray array];
    _tableView4 = [[UITableView alloc]initWithFrame:CGRectMake(mainScreenSize.width*3, 0, mainScreenSize.width, mainScreenSize.height-64-45)];
    _tableView4.dataSource = self;
    _tableView4.delegate = self;
    [_tableView4 setBackgroundColor:[AppConfig colorWithHexString:@"#f5f5f5"]];
    [_tableView4 setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.scrollView addSubview:_tableView4];
    _tableView4.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^(void){
        [weakSelf getOrderListByStatus:MyOrderListStatus4 withPage:_currentPage4+1];
    }];
    MJRefreshGifHeader *header4 = [AppConfig getCustomMJRefreshGifHeader];
    [header4 setRefreshingBlock:^(void){
        [weakSelf getOrderListByStatus:MyOrderListStatus4 withPage:1];
    }];
    _tableView4.mj_header = header4;
    //[self getOrderListByStatus:MyOrderListStatus4 withPage:1];
    
    _dataSource5 = [NSMutableArray array];
    _tableView5 = [[UITableView alloc]initWithFrame:CGRectMake(mainScreenSize.width*4, 0, mainScreenSize.width, mainScreenSize.height-64-45)];
    _tableView5.dataSource = self;
    _tableView5.delegate = self;
    [_tableView5 setBackgroundColor:[AppConfig colorWithHexString:@"#f5f5f5"]];
    [_tableView5 setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.scrollView addSubview:_tableView5];
    _tableView5.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^(void){
        [weakSelf getOrderListByStatus:MyOrderListStatus5 withPage:_currentPage5+1];
    }];
    MJRefreshGifHeader *header5 = [AppConfig getCustomMJRefreshGifHeader];
    [header5 setRefreshingBlock:^(void){
        [weakSelf getOrderListByStatus:MyOrderListStatus5 withPage:1];
    }];
    _tableView5.mj_header = header5;
    //[self getOrderListByStatus:MyOrderListStatus5 withPage:1];
}
-(void)backPage{
    //获取通知中心单例对象
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center removeObserver:self name:@"MyOrderListControllerNSNotificationCenter" object:nil];
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewDidAppear:(BOOL)animated{
    //获取通知中心单例对象
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    //添加当前类对象为一个观察者，name和object设置为nil，表示接收一切通知
    [center addObserver:self selector:@selector(MyOrderListControllerDelegatePayCallBack:) name:@"MyOrderListControllerNSNotificationCenter" object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView==_tableView1) {
        return _dataSource1.count;
    }else if (tableView==_tableView2) {
        return _dataSource2.count;
    }else if (tableView==_tableView3) {
        return _dataSource3.count;
    }else if (tableView==_tableView4) {
        return _dataSource4.count;
    }else if (tableView==_tableView5) {
        return _dataSource5.count;
    }
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    int buttonW = (mainScreenSize.width-90)/3-10+20;
    buttonW = buttonW+120;
    return buttonW;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * cellID = @"MyOrderCell";
    MyOrderCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:cellID owner:self options:nil] firstObject];
    }
    int buttonW = (mainScreenSize.width-90)/3-10+20;
    buttonW = buttonW+120;
    [cell setFrame:CGRectMake(0, 0, mainScreenSize.width, buttonW)];
    NSDictionary * orderInfo;
    if (_tableView1==tableView) {
        [cell setStatus:MyOrderListStatus1];
        orderInfo = _dataSource1[indexPath.row];
    }else if (_tableView2==tableView) {
        [cell setStatus:MyOrderListStatus2];
        orderInfo = _dataSource2[indexPath.row];
    }else if (_tableView3==tableView) {
        [cell setStatus:MyOrderListStatus3];
        orderInfo = _dataSource3[indexPath.row];
    }else if (_tableView4==tableView) {
        [cell setStatus:MyOrderListStatus4];
        orderInfo = _dataSource4[indexPath.row];
    }else if (_tableView5==tableView) {
        [cell setStatus:MyOrderListStatus5];
        orderInfo = _dataSource5[indexPath.row];
    }
    [cell setIndexPath:indexPath];
    [cell setOrderInfo:orderInfo];
    [cell setType:4];
    [cell updateCellContentUI];//更新Cell内容
    
    cell.delegate = self;
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * orderInfo;
    if (_tableView1==tableView) {
        orderInfo = _dataSource1[indexPath.row];
        _status = MyOrderListStatus1;
    }else if (_tableView2==tableView) {
        orderInfo = _dataSource2[indexPath.row];
        _status = MyOrderListStatus2;
    }else if (_tableView3==tableView) {
        orderInfo = _dataSource3[indexPath.row];
        _status = MyOrderListStatus3;
    }else if (_tableView4==tableView) {
        orderInfo = _dataSource4[indexPath.row];
        _status = MyOrderListStatus4;
    }else if (_tableView5==tableView) {
        orderInfo = _dataSource5[indexPath.row];
        _status = MyOrderListStatus5;
    }
    _indexPathPay = indexPath;
    OrderDetailController * orderDetail = [[OrderDetailController alloc]init];
    [orderDetail setOrderNo:[orderInfo objectForKey:@"uuid"]];
    [orderDetail setStatu:[[orderInfo objectForKey:@"sellerStatus"] intValue]];
    //[orderDetail setOrderInfo:orderInfo];
    [self.navigationController pushViewController:orderDetail animated:YES];
}

#pragma -mark MyOrderCell Delegate
-(void)MyOrderCell:(MyOrderCell *)cell deleteIndexPath:(NSIndexPath *)indexPath{
    if (cell.status==MyOrderListStatus1) {
        [_dataSource1 removeObjectAtIndex:indexPath.row];
        [_tableView1 reloadData];
    }else if (cell.status==MyOrderListStatus2) {
        [_dataSource2 removeObjectAtIndex:indexPath.row];
        [_tableView2 reloadData];
    }else if (cell.status==MyOrderListStatus3){
        [_dataSource3 removeObjectAtIndex:indexPath.row];
        [_tableView3 reloadData];
    }else if (cell.status==MyOrderListStatus4){
        [_dataSource4 removeObjectAtIndex:indexPath.row];
        [_tableView4 reloadData];
    }else if (cell.status==MyOrderListStatus5){
        [_dataSource5 removeObjectAtIndex:indexPath.row];
        [_tableView5 reloadData];
    }
}
-(void)MyOrderCell:(MyOrderCell *)cell EvalIndexPath:(NSIndexPath *)indexPath{
    NSArray * map = [cell.orderInfo objectForKey:@"map"];
    if(map!=nil && map.count>0){
        _status = cell.status;
        NSString * orderId = [cell.orderInfo objectForKey:@"uuid"];
        EvalProductListController * evalList = [[EvalProductListController alloc]init];
        [evalList setOrderId:orderId];
        [evalList setDataSource:[NSMutableArray arrayWithArray:map]];
        [self.navigationController pushViewController:evalList animated:YES];
    }
}

-(void)MyOrderCell:(MyOrderCell *)cell CancelReasonIndexPath:(NSIndexPath *)indexPath{
    NSArray * map = [cell.orderInfo objectForKey:@"map"];
    NSLog(@"-------cell.orderInfo = %@",cell.orderInfo);
    
    if(map!=nil && map.count>0){
        NSString * cancelReasonStr = [cell.orderInfo objectForKey:@"orderMsg"];
        CancelReasonViewController * cancelReasonVC = [[CancelReasonViewController alloc]init];
        [cancelReasonVC setCancelReasonStr:cancelReasonStr];
        [self.navigationController pushViewController:cancelReasonVC animated:YES];
    }
}


#pragma -mark MyOrderCell Delegate
-(void)MyOrderCell:(MyOrderCell *)cell ConfirmIndexPath:(NSIndexPath *)indexPath{
    [self reloadCell:cell.status withSellerStatus:@"5" withIndexPath:indexPath];
}
-(void)MyOrderCell:(MyOrderCell *)cell CancelIndexPath:(NSIndexPath *)indexPath{
    [self reloadCell:cell.status withSellerStatus:@"-1" withIndexPath:indexPath];
}
-(void)MyOrderCell:(MyOrderCell *)cell PayIndexPath:(NSIndexPath *)indexPath{
    _indexPathPay = indexPath;
    _status = cell.status;
//    NSString * orderId = [cell.orderInfo objectForKey:@"uuid"];
//    float payedMoney = [[cell.orderInfo objectForKey:@"payedMoney"] floatValue];
//    PayOrderController * payOrder = [[PayOrderController alloc]init];
//    [payOrder setOrderNo:orderId];
//    [payOrder setOrderPrice:[NSString stringWithFormat:@"%0.2f",payedMoney]];
//    [payOrder setIsPersonal:@"1"];
//    payOrder.payOrderDelegate = self;
//    [self.navigationController pushViewController:payOrder animated:YES];
    
    OrderDetailController * orderDetail = [[OrderDetailController alloc]init];
    [orderDetail setOrderNo:[cell.orderInfo objectForKey:@"uuid"]];
    [orderDetail setStatu:[[cell.orderInfo objectForKey:@"sellerStatus"] intValue]];
    //[orderDetail setOrderInfo:cell.orderInfo];
    [self.navigationController pushViewController:orderDetail animated:YES];
}
#pragma -mark 退款
-(void)MyOrderCell:(MyOrderCell *)cell RefundIndexPath:(NSIndexPath *)indexPath{
    OrderRefundController * orderRefund = [[OrderRefundController alloc]init];
    [orderRefund setOrderInfo:cell.orderInfo];
    [self.navigationController pushViewController:orderRefund animated:YES];
}
//通知中心接收对象
-(void)MyOrderListControllerDelegatePayCallBack:(NSNotification *)notification{
    NSDictionary * userInfo = [notification userInfo];
    NSString * send = [userInfo objectForKey:@"send"];
    NSLog(@"===isSuccess:%@",send);
    if (send!=nil) {
        if ([send isEqualToString:@"pay"]) {
            //支付回调
            [self reloadCell:_status withSellerStatus:@"2" withIndexPath:_indexPathPay];
        }else if ([send isEqualToString:@"eval"]){
            //评价回调
            if (_status==MyOrderListStatus1) {
                [_tableView1.mj_header beginRefreshing];
            }else if(_status==MyOrderListStatus5){
                [_tableView5.mj_header beginRefreshing];
            }
        }
    }
}
//统一刷新Cell
-(void)reloadCell:(int)status withSellerStatus:(NSString *)sellerStatus withIndexPath:(NSIndexPath *)indexPath{
    NSMutableDictionary * orderInfo;
    //当status=0时是查询全部，所以只需要刷新，否则从当前数组中移除
    if (status==MyOrderListStatus1) {
        orderInfo = [NSMutableDictionary dictionaryWithDictionary:_dataSource1[indexPath.row]];
        [orderInfo setObject:sellerStatus forKey:@"sellerStatus"];
        _dataSource1[indexPath.row] = orderInfo;
        [_tableView1 reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    }else if (status==MyOrderListStatus2) {
        [_dataSource2 removeObjectAtIndex:indexPath.row];
        [_tableView2 reloadData];
    }else if (status==MyOrderListStatus3){
        [_dataSource3 removeObjectAtIndex:indexPath.row];
        [_tableView3 reloadData];
    }else if (status==MyOrderListStatus4){
        [_dataSource4 removeObjectAtIndex:indexPath.row];
        [_tableView4 reloadData];
    }else if (status==MyOrderListStatus5){
        [_dataSource5 removeObjectAtIndex:indexPath.row];
        [_tableView5 reloadData];
    }
}

#pragma -mark ScrollView
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (scrollView==_scrollView){
        CGPoint offset = scrollView.contentOffset;
        _currentPage = (int)offset.x/_scrollView.frame.size.width;
        //根据滑动选择按钮
        UIButton * button = (UIButton *)[_topVIew viewWithTag:100+_currentPage];
        [self topBtnClick:button];
    }
}
//监测contentOffset.y的变化
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView==_scrollView){
        CGPoint offset = scrollView.contentOffset;
        int offsetX = offset.x/5;
        //设置buttonLine偏移量
        [self.lineBtn setFrame:CGRectMake(offsetX, self.lineBtn.frame.origin.y,_topVIew.frame.size.width/5, 2)];
    }
}

#pragma - mark 
-(void)getOrderListInit{
    [self showHudInView:self.view hint:nil];
    NSString * _userId = [AppConfig getUserInfoByKey:@"uuid"];
    NSMutableDictionary * param = [NSMutableDictionary dictionaryWithObjectsAndKeys:tokenString,@"token", nil];
    [param setObject:_userId forKey:@"userId"];
    [param setObject:@"4" forKey:@"userType"];
    [param setObject:@"0" forKey:@"status"];
    [param setObject:@"1" forKey:@"pageNo"];
    [param setObject:_pageSize forKey:@"pageSize"];
    NSLog(@"----------%@",param);
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:_BaseURL]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url_OrderList_buyer parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        NSLog(@"====data:%@",data);
        [self hideHud];
        if (error) {
//            NSLog(@"====error:%@",error);
//            [self showHint:[NSString stringWithFormat:@"%@",error.localizedDescription]];
            return;
        }
        NSString * code = [NSString stringWithFormat:@"%@",[data objectForKey:@"error"]];
        if ([code isEqualToString:@"0"]) {
            NSArray * arr = [data objectForKey:@"data"];
            if([arr isEqual:[NSNull null]]){
                
            }else{
                _dataSource1 = [NSMutableArray arrayWithArray:arr];
                [_tableView1 reloadData];
                
                for (NSDictionary * dict in arr) {
                    int status = [[dict objectForKey:@"status"] intValue];
                    if (status==1) {
                        [_dataSource2 addObject:dict];
                    }else if (status==3){
                        [_dataSource3 addObject:dict];
                    }else if (status==5){
                        [_dataSource4 addObject:dict];
                    }else if (status==6){
                        [_dataSource5 addObject:dict];
                    }
                }
                [_tableView2 reloadData];
                [_tableView3 reloadData];
                [_tableView4 reloadData];
                [_tableView5 reloadData];
            }
            
        }else{
//            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"message"]];
//            [self showHint:info];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull   error) {
        NSLog(@"====error:%@",error);
//        [self hideHud];
//        [self showHint:[NSString stringWithFormat:@"%@",error.localizedDescription]];
    }];
}
#pragma - mark
-(void)getOrderListByStatus:(int)status withPage:(int)currentPage{
    
    [self hideHud];
    [self showHudInView:self.view hint:nil];
    NSString * _userId = [AppConfig getUserInfoByKey:@"uuid"];
    NSMutableDictionary * param = [NSMutableDictionary dictionaryWithObjectsAndKeys:tokenString,@"token", nil];
    [param setObject:_userId forKey:@"userId"];
    [param setObject:@"4" forKey:@"userType"];
    [param setObject:[NSString stringWithFormat:@"%d",status] forKey:@"status"];
    [param setObject:[NSString stringWithFormat:@"%d",currentPage] forKey:@"pageNo"];
    [param setObject:_pageSize forKey:@"pageSize"];
    if (status==5) {
        [param setObject:@"0" forKey:@"evalStatus"];
    }
    
    NSLog(@"===param:%@",param);
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:_BaseURL]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url_OrderList_buyer parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        NSLog(@"====data:%@",data);
        if (status==MyOrderListStatus1) {
            [_tableView1.mj_header endRefreshing];
            [_tableView1.mj_footer endRefreshing];
        }else if (status==MyOrderListStatus2) {
            [_tableView2.mj_header endRefreshing];
            [_tableView2.mj_footer endRefreshing];
        }else if (status==MyOrderListStatus3){
            [_tableView3.mj_header endRefreshing];
            [_tableView3.mj_footer endRefreshing];
        }else if (status==MyOrderListStatus4){
            [_tableView4.mj_header endRefreshing];
            [_tableView4.mj_footer endRefreshing];
        }else if (status==MyOrderListStatus5){
            [_tableView5.mj_header endRefreshing];
            [_tableView5.mj_footer endRefreshing];
        }
        [self hideHud];
        if (error) {
//            NSLog(@"====error:%@",error);
//            [self showHint:[NSString stringWithFormat:@"%@",error.localizedDescription]];
            return;
        }
        NSString * code = [NSString stringWithFormat:@"%@",[data objectForKey:@"error"]];
        if ([code isEqualToString:@"0"]) {
            NSArray * arr = [data objectForKey:@"data"];
            if (currentPage==1) {
                if (status==MyOrderListStatus1) {
                    _currentPage1 = currentPage;
                    [_dataSource1 removeAllObjects];
                }else if (status==MyOrderListStatus2) {
                    _currentPage2 = currentPage;
                    [_dataSource2 removeAllObjects];
                }else if (status==MyOrderListStatus3){
                    _currentPage3 = currentPage;
                    [_dataSource3 removeAllObjects];
                }else if (status==MyOrderListStatus4){
                    _currentPage4 = currentPage;
                    [_dataSource4 removeAllObjects];
                }else if (status==MyOrderListStatus5){
                    _currentPage5 = currentPage;
                    [_dataSource5 removeAllObjects];
                }
            }
            if (arr!=nil && arr.count>0) {
                if (status==MyOrderListStatus1) {
                    _currentPage1 = currentPage;
                    [_dataSource1 addObjectsFromArray:arr];
                    [_tableView1 reloadData];
                }else if (status==MyOrderListStatus2) {
                    _currentPage2 = currentPage;
                    [_dataSource2 addObjectsFromArray:arr];
                    [_tableView2 reloadData];
                }else if (status==MyOrderListStatus3){
                    _currentPage3 = currentPage;
                    [_dataSource3 addObjectsFromArray:arr];
                    [_tableView3 reloadData];
                }else if (status==MyOrderListStatus4){
                    _currentPage4 = currentPage;
                    [_dataSource4 addObjectsFromArray:arr];
                    [_tableView4 reloadData];
                }else if (status==MyOrderListStatus5){
                    _currentPage5 = currentPage;
                    [_dataSource5 addObjectsFromArray:arr];
                    [_tableView5 reloadData];
                }
            }else{
                if (currentPage==1) {
                    if (status==MyOrderListStatus1) {
                        [_tableView1 reloadData];
                    }else if (status==MyOrderListStatus2) {
                        [_tableView2 reloadData];
                    }else if (status==MyOrderListStatus3){
                        [_tableView3 reloadData];
                    }else if (status==MyOrderListStatus4){
                        [_tableView4 reloadData];
                    }else if (status==MyOrderListStatus5){
                        [_tableView5 reloadData];
                    }
                }
                if (status==MyOrderListStatus1) {
                    [_tableView1.mj_footer endRefreshingWithNoMoreData];
                }else if (status==MyOrderListStatus2) {
                    [_tableView2.mj_footer endRefreshingWithNoMoreData];
                }else if (status==MyOrderListStatus3){
                    [_tableView3.mj_footer endRefreshingWithNoMoreData];
                }else if (status==MyOrderListStatus4){
                    [_tableView4.mj_footer endRefreshingWithNoMoreData];
                }else if (status==MyOrderListStatus5){
                    [_tableView5.mj_footer endRefreshingWithNoMoreData];
                }
            }
        }else{
//            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"message"]];
//            [self showHint:info];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull   error) {
        NSLog(@"====error:%@",error);
        [self hideHud];
        if (status==MyOrderListStatus1) {
            [_tableView1.mj_header endRefreshing];
            [_tableView1.mj_footer endRefreshing];
        }else if (status==MyOrderListStatus2) {
            [_tableView2.mj_header endRefreshing];
            [_tableView2.mj_footer endRefreshing];
        }else if (status==MyOrderListStatus3){
            [_tableView3.mj_header endRefreshing];
            [_tableView3.mj_footer endRefreshing];
        }else if (status==MyOrderListStatus4){
            [_tableView4.mj_header endRefreshing];
            [_tableView4.mj_footer endRefreshing];
        }else if (status==MyOrderListStatus5){
            [_tableView5.mj_header endRefreshing];
            [_tableView5.mj_footer endRefreshing];
        }
        [self showHint:@"获取订单列表失败"];
    }];
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
